Fix JNI affinity mask copying and make JNA initialisation more resilient - #192
Open
peter-lawrey wants to merge 1 commit into
Open
Fix JNI affinity mask copying and make JNA initialisation more resilient#192peter-lawrey wants to merge 1 commit into
peter-lawrey wants to merge 1 commit into
Conversation
james-mcsherry
approved these changes
Nov 28, 2025
tgd
removed their request for review
April 28, 2026 08:59
Bound native array copies and report syscall failures with errno context. Keep UTF-8 lock metadata and accurate calling-thread affinity contracts. Handle unavailable or incompatible JNA and use a public version getter that works with its explicit Java module. Add enabled native-mask, failure, classpath and module regression coverage. Align native tests with the ARM32 build exclusion and preserve full-mask parity testing when no short permitted-CPU mask is available. Squashed from 03211b7 without changing the source tree. Linux validation on that tree: Java 21 reactor 69 passed, three skipped; Java 8 focused nine passed, one module-test skip.
peter-lawrey
force-pushed
the
adv/develop
branch
from
September 9, 2026 16:16
03211b7 to
3c92318
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix JNI affinity-mask copying: the old setter read a full
cpu_set_teven when the Java array was shorter, and getter/setter access throughGetByteArrayElementswas not released. Zero the native mask and use bounded array-region copies. Failedsched_setaffinitycalls throw a Java exception with the thread selector, input length and immediately capturederrno.Read JNA's runtime version through
MethodHandles.publicLookup().findStaticGetter(...). This accesses the inherited public field throughNativewithout requiring the JNA module to open its package. At the JNA initialisation boundary, recover from its plainErrorfor an incompatible native library while explicitly propagatingVirtualMachineError,ThreadDeathandAssertionError. Retain fallback for absent JNA and native-loading failures, accurate Linux calling-thread contracts, the small POSIX initialisation adjustment and UTF-8 lock metadata.The final delta against develop
6a57105d9167fbf66dceea6a1b257df211c56959is eleven files, +459/-83. The original clock test and required JNA import are restored, and the newly callable timer wrapper is removed. The merged README work from #198 is preserved. The additional POM dependency is test-onlyjna-jpms:5.17.0; the normal JNA version remains BOM-managed and resolved to 5.5.0 in these runs.Enabled coverage uses real compiled project classes/native code and fresh JVMs:
errno=22and unchanged affinity, and 10,000 repeated reads. Mask-changing probes restore and verify the exact original mask infinally.-Xcheck:jniwithout JNA on their classpath. Repeated reads are smoke coverage; they do not detect the old unreleased-array-access defect. Parity runs separately from the checker because old JNA binaries emit their own warnings.Erroris logged andNullAffinityis selected.jna-jpmsartifact from the module path with JNA removed from the classpath. Assert that its package is exported but not open, and that Linux JNA affinity works. Isolated classloaders also check propagation of injected VM, thread-termination and assertion errors.os.arch=arm) exclusion anddontMake. A missing library still fails on eligible hosts. If permitted CPUs require all 128 mask bytes, only the short-mask case skips; parity remains eligible.History was squashed to
3c92318500f568f37a647de5585b8c823033756cafter validation. Its Git tree is identical to tested head03211b75de04fd05fc000f87542d86694cfdd1df; the source and test results below are unchanged.Validation on 9 September 2026, Linux amd64, Maven 3.8.7 and GCC 13.3.0, at
03211b75de04fd05fc000f87542d86694cfdd1df:verify: 72 reported cases, 69 passed, three existing skips, no failures/errors/retries. All ten focused cases ran. Checkstyle, native compilation, packaging, Javadocs and licence checks passed.verify: nine passed, one expected module-test skip, no failures/errors/retries.os.arch=armin both Maven and test JVMs; native compilation is omitted and all four native cases skip without a library.dontMakebehaves likewise. An ordinary amd64 Surefire invocation without the library produces four expected assertion failures. These are eligibility controls on amd64, not ARM hardware qualification.Existing disabled/assumption-guarded legacy tests remain. Other platforms, clock accuracy and the full Java 8 reactor are unqualified; the fixed
cpu_set_tcapacity is unchanged. The high-CPU-only skip branch was source-reviewed, not exercised on suitable hardware. The native C++ is unchanged from the preceding reviewed head.